package com.zbp.model.vo;

import cn.hutool.core.util.ObjectUtil;
import com.zbp.model.Role;
import com.zbp.model.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Proxy;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 用户
 *
 * @Api注释上面的是jpa|下面的是MyBatis
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Proxy(lazy = false)
@ApiModel(value = "用户信息")
public class UserVO extends User implements Serializable, UserDetails {

    @ApiModelProperty(value = "用户角色")
    private List<Role> roleList;

    @Override
    public String getUsername() {
        return this.getName();
    }

    @Override
    public String getPassword() {
        return this.getPassWord();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.roleList;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return ObjectUtil.equal(this.getStatus(), 0) ? true : false;
    }
}
